package com.example.server.config;

import com.example.server.handle.MyHandshakeInterceptor;
import com.example.server.handle.MyWebSocketHandler;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Data
@ConfigurationProperties(prefix = "ws")
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    private String path;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(new MyWebSocketHandler(), path)
                .setAllowedOrigins("*")
                .addInterceptors(new MyHandshakeInterceptor());
    }
}

